clear all
set more off

*================================================================
* Table 1: Stated preferences
*================================================================

qui: include "do/ISSP.do"

*================================================================
* Table 2: Federal referenda
*================================================================

qui: include "do/referenda.do"

*================================================================
* Table 3: descriptive statistics
*================================================================

use "dta/data.dta", clear

qui: sum year
global y_max = r(max)
global y_min = r(min)
global y_count = ($y_max - $y_min)+1

g border = (dist >=-20 & dist <= 20)
g int_bfr = border * french

qui: include "do/sumstat.do"

*================================================================
* Table 4
*================================================================

global xpop "population foreigners young old"
global xeco "secondary tertiary agglo center dist_center tourist"
global xgeo "altitude_min altitude altitude_max area"
global xamen "lake castle wealthtax1940"
global xmigr "medinc gini high_educ mid_educ unemployment" // two variables (% top 1%-income taxpayers and % bottom 50%-income taxpayers) missing due to data confidentality

// mean-deviation

foreach var of varlist $xpop $xeco $xgeo $xamen $xmigr{
qui: sum `var' if (dist >=-40 & dist <= 40)
local m = r(mean)
g md_`var' = `var'-`m'
g fr_md_`var' = french*md_`var'
g bor_md_`var' = border*md_`var'
}

global xmdpop "md_population md_foreigners md_young md_old"
global xmdeco "md_secondary md_tertiary md_agglo md_center md_dist_center md_tourist"
global xmdgeo "md_altitude_min md_altitude md_altitude_max md_area"
global xmdamen "md_lake md_castle md_wealthtax1940"
global xmdmigr "md_medinc md_gini md_high_educ md_mid_educ md_unemployment"

global xintpop "fr_md_population fr_md_foreigners fr_md_young fr_md_old bor_md_population bor_md_foreigners bor_md_young bor_md_old"
global xinteco "fr_md_secondary fr_md_tertiary fr_md_agglo fr_md_center fr_md_dist_center fr_md_tourist bor_md_secondary bor_md_tertiary bor_md_agglo bor_md_center bor_md_dist_center bor_md_tourist"
global xintgeo "fr_md_altitude_min fr_md_altitude fr_md_altitude_max fr_md_area bor_md_altitude_min bor_md_altitude bor_md_altitude_max bor_md_area"
global xintamen "fr_md_lake fr_md_castle fr_md_wealthtax1940 bor_md_lake  bor_md_castle bor_md_wealthtax1940"
global xintmigr "fr_md_medinc fr_md_gini fr_md_high_educ fr_md_mid_educ fr_md_unemployment bor_md_medinc bor_md_gini bor_md_high_educ bor_md_mid_educ bor_md_unemployment"

global xfrpop "fr_md_population fr_md_foreigners fr_md_young fr_md_old"
global xfreco "fr_md_secondary fr_md_tertiary fr_md_agglo fr_md_center fr_md_dist_center fr_md_tourist"
global xfrgeo "fr_md_altitude_min fr_md_altitude fr_md_altitude_max fr_md_area"
global xframen "fr_md_lake fr_md_castle fr_md_wealthtax1940"
global xfrmigr "fr_md_medinc fr_md_gini fr_md_high_educ fr_md_mid_educ fr_md_unemployment"

cap file close TA
file open TA using "tables/AET2005_T4.tex", write replace
file write TA "& (1) & (2) & (3) & (4) & (5) & (6) \\ \hline " _n

*** Panel A

foreach var in md_taxmult {
global X ""
global depvar = "`var'"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test french border int_bfr 
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelA, replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2 sortvar(int_bfr border french pref_left $propx) nocons ctitle("no controls", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test  $xmdgeo $xmdamen
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelA, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdpop $xmdeco
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelA, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xintgeo $xintamen $xintpop $xinteco 
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelA, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

}

*** Panel B

foreach var in pref_left {
global X ""
global depvar =  "`var'"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test french border int_bfr 
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelB, replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("no controls", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test  $xmdgeo $xmdamen
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelB, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdpop $xmdeco
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelB, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X   i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xintgeo $xintamen $xintpop $xinteco 
local Ft = r(p)
outreg2 int_bfr border french using tables/T4_panelB, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

}

*** Panel C

foreach var in md_taxmult {
global X "pref_left"
global depvar =  "`var'"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test french border int_bfr 
local Ft = r(p)
outreg2 int_bfr border french pref_left using tables/T4_panelC, replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("no controls", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen pref_left"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test  $xmdgeo $xmdamen
local Ft = r(p)
outreg2 int_bfr border french pref_left using tables/T4_panelC, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco pref_left"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdpop $xmdeco
local Ft = r(p)
outreg2 int_bfr border french pref_left using tables/T4_panelC, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco pref_left"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xintgeo $xintamen $xintpop $xinteco 
local Ft = r(p)
outreg2 int_bfr border french pref_left using tables/T4_panelC, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n
}

file close TA


*================================================================
* Table 5 - controls interacted with french
*================================================================

foreach width in 10 15 20{
local w = `width'
local hbound = `width'
if `hbound' == `width'{
local lbound = 0
}
else{
local lbound = `hbound'-`width'+1
}

while `hbound' <= 45{

disp in red "The upper bound is `hbound'"
disp in red "The lower bound is `lbound'"

qui: sum gdenr if french == 0 & ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound'))
local mun_g = round(r(N)/$y_count)
sum dist if french == 0 & ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound'))

qui: sum gdenr if french == 1 & ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound'))
local mun_l = round(r(N)/$y_count)
sum dist if french == 1 & ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound'))

xi: ivreg2 md_taxmult french i.year if ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound')), cluster(gdenr year)
outreg2  french using tables/T5_`hbound'_`width', replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) nor2   nocons addstat("Nb of French municipalities", `mun_l', "Nb of German municipalities", `mun_g', "Nb of years", $y_count) ctitle("`hbound'" "`width'")

xi: ivreg2 md_taxmult french $xmdgeo $xmdamen $xmdpop $xmdeco $xfrgeo $xframen $xfrpop $xfreco  i.year if ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound')), cluster(gdenr year)
outreg2  french using tables/T5_`hbound'_`width', tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) nor2   nocons addstat("Nb of French municipalities", `mun_l', "Nb of German municipalities", `mun_g', "Nb of years", $y_count) ctitle("`hbound'" "`width'")

xi: ivreg2 pref_left french i.year if ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound')), cluster(gdenr year)
outreg2  french using tables/T5_`hbound'_`width',  tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) nor2   nocons addstat("Nb of French municipalities", `mun_l', "Nb of German municipalities", `mun_g', "Nb of years", $y_count) ctitle("`hbound'" "`width'")

xi: ivreg2 pref_left french $xmdgeo $xmdamen $xmdpop $xmdeco $xfrgeo $xframen $xfrpop $xfreco i.year if ((dist>=-`hbound' & dist <= -(`lbound')) | (dist >= (`lbound') & dist <= `hbound')), cluster(gdenr year)
outreg2  french using tables/T5_`hbound'_`width',  tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) nor2   nocons addstat("Nb of French municipalities", `mun_l', "Nb of German municipalities", `mun_g', "Nb of years", $y_count) ctitle("`hbound'" "`width'")

local hbound = `hbound' + `width'
local lbound = `lbound' + `width'+0.0001
}
}

*================================================================
* Table A.1 - migration-related controls
*================================================================

cap file close TA
file open TA using "tables/AET2005_TA1.tex", write replace
file write TA "& (1) & (2) & (3) & (4) & (5) & (6) \\ \hline " _n

*** Panel A

foreach var in md_taxmult {
global depvar = "`var'"

global X ""
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test french border int_bfr 
local Ft = r(p)
outreg2 int_bfr border french using tables/TA1_panelA, replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2 sortvar(int_bfr border french pref_left $propx) nocons ctitle("no controls", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco
local Ft = r(p)
outreg2 int_bfr border french using tables/TA1_panelA,  tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xmdmigr $xintgeo $xintamen $xintpop $xinteco $xintmigr"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdmigr $xintmigr
local Ft = r(p)
outreg2 int_bfr border french using tables/TA1_panelA, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ + endo", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

}

*** Panel B

foreach var in pref_left{
global depvar = "`var'"

global X ""
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test french border int_bfr 
local Ft = r(p)
outreg2 int_bfr border french using tables/TA1_panelB, replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2 sortvar(int_bfr border french pref_left $propx) nocons ctitle("no controls", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test  $xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco 
local Ft = r(p)
outreg2 int_bfr border french using tables/TA1_panelB,  tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xmdmigr $xintgeo $xintamen $xintpop $xinteco $xintmigr"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdmigr $xintmigr
local Ft = r(p)
outreg2 int_bfr border french using tables/TA1_panelB, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ + endo", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n
}

*** Panel C

foreach var in md_taxmult {
global X "pref_left"
global depvar =  "`var'"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test french border int_bfr 
local Ft = r(p)
outreg2 int_bfr border french pref_left  using tables/TA1_panelC, replace tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("no controls", " ", " ") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco pref_left"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco pref_left
local Ft = r(p)
outreg2 int_bfr border french pref_left using tables/TA1_panelC, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xmdmigr $xintgeo $xintamen $xintpop $xinteco $xintmigr pref_left"
do "do/AET2005.do"
xi: ivreg2 `var' french border int_bfr $X  i.year if (dist >=-40 & dist <= 40), cluster(gdenr year)
local FGaB =  _b[french]+_b[int_bfr]
test _b[french]+_b[int_bfr]=0
local PFGaB =r(p)
local BaF =  _b[border]+_b[int_bfr]
test _b[border]+_b[int_bfr]=0
local PBaF =r(p)
test   $xmdmigr $xintmigr 
local Ft = r(p)
outreg2 int_bfr border french pref_left using tables/TA1_panelC, tex(frag) alpha(0.01, 0.05, 0.10) bdec(3) tdec(3) adec(3) adjr2  sortvar(int_bfr border french pref_left $propx) nocons ctitle("geo + amenities", "+ pop + econ + endo", "+ interaction terms") addstat("F-test on added controls",`Ft', "AET 2005 Implied Ratio", $C6)

file write TA "& $C1 & $C2 & $C3 & $C4 & $C5 & $C6 \\ " _n
}

file close TA

*================================================================
* Table A.2 - changes-in-changes model with covariates
* The command cic has been written by Blaise Melly and Giulia Santangelo. Please email Blaise Melly for the ado file.
* Bootstrapping standard errors is very computing intensive. You may want to change the reps(500) option
*================================================================

log using "tables/TA2.log", replace

preserve
keep if (dist >=-40 & dist <= 40)

xi: cic md_taxmult i.year , group(french) time(border) quantiles(0.25(0.25)0.75) reps(500)

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco"
xi: cic md_taxmult i.year $X , group(french) time(border) quantiles(0.25(0.25)0.75)  reps(500)

global X "$xmdgeo $xmdamen $xmdpop $xmdeco $xintgeo $xintamen $xintpop $xinteco $xmdmigr $xintmigr"
xi: cic md_taxmult i.year $X , group(french) time(border) quantiles(0.25(0.25)0.75)  reps(500)
restore

log close
